package com.designed.pattern.behavioral.observer;

import java.util.Observable;
import java.util.Observer;

/**
 * jdk 原生类提供
 * @author yifei
 * @description
 * @date 2024/1/4
 **/
public class MyTest {
    public static void main(String[] args) {
        MyObservable myObserver = new MyObservable("朱一飞");
        myObserver.addObserver(new MyObserver());
        myObserver.setAction();
    }
}

class MyObserver implements Observer {
    @Override
    public void update(Observable o, Object arg) {
        System.out.println("666: " + ((MyObservable) o).name);
    }
}

class MyObservable extends Observable {
    String name;
    String action;

    public MyObservable(String name) {
        this.name = name;
    }

    public void setAction() {
        this.action = "zhuyifei";
        super.setChanged();
        super.notifyObservers(666);
    }
}